package p.ithorns.integration.hazelcast.mqtt;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * BeaconRaw
 * 信标源数据
 *
 * @author liuhaitao
 * @version 1.0
 * @date 2022/3/12 15:04
 */
//@DataObject(generateConverter = true)
@Getter
@Setter
@Builder
public class BeaconRaw implements Serializable {

    /**
     * 信标编号
     * Beacon ID  4字节
     */
    private String beaconCode;

    /**
     * AntExt
     * 1字节
     * bit7	  Ext
     * bit6	  默认0
     * bit5-0 固定1
     *
     * Ext为1时包含 IntPwr和Volt
     */
    private int ext;

    /**
     * IntPwr
     * bit7-4 Interval
     */
    @JsonIgnore
    private String interval;

    /**
     * IntPwr
     * bit3-0 TxPwr
     */
    private int txPwr;

    /**
     * 电压值
     * 1字节
     */
    private double volt;

    /**
     * 信号值
     * Beacon RSSI
     * 1字节
     */
    private int rssi;

    public BeaconRaw() {
    }

    public BeaconRaw(String beaconCode, int rssi) {
        this.beaconCode = beaconCode;
        this.rssi = rssi;
    }

    public BeaconRaw(String beaconCode, int ext, String interval, int txPwr, double volt, int rssi) {
        this.beaconCode = beaconCode;
        this.ext = ext;
        this.interval = interval;
        this.txPwr = txPwr;
        this.volt = volt;
        this.rssi = rssi;
    }

//    public BeaconRaw(JsonObject json) {
//        BeaconRawConverter.fromJson(json, this);
//    }
//
//    public JsonObject toJson() {
//        JsonObject json = new JsonObject();
//        BeaconRawConverter.toJson(this, json);
//        return json;
//    }

    @Override
    public String toString() {
        return "{" +
                "beaconCode:'" + beaconCode + '\'' +
                ", rssi:" + rssi +
                "}";
    }

}
